ABAP Select data from SAP table FMSAMVENDOR_HDR into internal table

Get Example source ABAP code based on a different SAP table
  

Below is a number of ABAP code snippets to demonstrate how to select data from SAP FMSAMVENDOR_HDR table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to FMSAMVENDOR_HDR. See here for more generic Select statement tips.

Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.

There is also a full declaration of the FMSAMVENDOR_HDR table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.

DATA: IT_FMSAMVENDOR_HDR TYPE STANDARD TABLE OF FMSAMVENDOR_HDR,
      WA_FMSAMVENDOR_HDR TYPE FMSAMVENDOR_HDR,
      GD_STR TYPE STRING.

DATA: lo_typedescr type REF TO cl_abap_typedescr.
DATA: lv_fieldname type fieldname.

FIELD-SYMBOLS: <FIELD> TYPE any.
FIELD-SYMBOLS: <FMSAMVENDOR_HDR> TYPE FMSAMVENDOR_HDR.

*Process all fields in table header/work area as string values
  PERFORM process_as_string_field_values CHANGING wa_FMSAMVENDOR_HDR.

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM FMSAMVENDOR_HDR
  INTO TABLE IT_FMSAMVENDOR_HDR.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM FMSAMVENDOR_HDR
*  INTO TABLE @DATA(IT_FMSAMVENDOR_HDR2).
*--Further methods of using ABAP code to  select data from SAP database tables

*You can also declare the header/work area using the in-line DATA declaration method
READ TABLE IT_FMSAMVENDOR_HDR INDEX 1 INTO DATA(WA_FMSAMVENDOR_HDR2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_FMSAMVENDOR_HDR ASSIGNING <FMSAMVENDOR_HDR>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<FMSAMVENDOR_HDR>-MANDT = 1.
<FMSAMVENDOR_HDR>-SAM_UE_ID = 1.
<FMSAMVENDOR_HDR>-SAM_EFT_IND = 1.
<FMSAMVENDOR_HDR>-DUNS = 1.
<FMSAMVENDOR_HDR>-CAGE = 1.
ENDLOOP.

LOOP AT IT_FMSAMVENDOR_HDR INTO WA_FMSAMVENDOR_HDR.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_FMSAMVENDOR_HDR-DODAAC, sy-vline,
WA_FMSAMVENDOR_HDR-PUR_REG_CODE, sy-vline,
WA_FMSAMVENDOR_HDR-REGSTAT, sy-vline,
WA_FMSAMVENDOR_HDR-REGDATE, sy-vline,
WA_FMSAMVENDOR_HDR-EXPDATE, sy-vline,
WA_FMSAMVENDOR_HDR-LASTUPDATE, sy-vline.
ENDLOOP. *Add any further fields from structure WA_FMSAMVENDOR_HDR you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_FMSAMVENDOR_HDR TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_FMSAMVENDOR_HDR INTO WA_FMSAMVENDOR_HDR. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_FMSAMVENDOR_HDR_STR,
MANDT TYPE STRING,
SAM_UE_ID TYPE STRING,
SAM_EFT_IND TYPE STRING,
DUNS TYPE STRING,
CAGE TYPE STRING,
DODAAC TYPE STRING,
PUR_REG_CODE TYPE STRING,
REGSTAT TYPE STRING,
REGDATE TYPE STRING,
EXPDATE TYPE STRING,
LASTUPDATE TYPE STRING,
ACTDATE TYPE STRING,
BUSNAME TYPE STRING,
DBANAME TYPE STRING,
DBOPENDATAFLG TYPE STRING,
SOURCE TYPE STRING,
DEPARTMENT_CODE TYPE STRING,
HIER_DEP_CODE TYPE STRING,
HIER_DEP_NAME TYPE STRING,
HIER_AGCY_CODE TYPE STRING,
HIER_AGCY_NAME TYPE STRING,
HIER_OFFICE_CODE TYPE STRING,
TAXPAYERNAME TYPE STRING,
TAXIDTYPE TYPE STRING,
TAXID TYPE STRING,
URL TYPE STRING,
DIVNAME TYPE STRING,
DIVNUM TYPE STRING,
BUSSTART TYPE STRING,
FISCEND TYPE STRING,
AGCY_BUS_PUR TYPE STRING,
ENTSTRUCT TYPE STRING,
STATEINC TYPE STRING,
COUNTRYINC TYPE STRING,
COSECLVL TYPE STRING,
EMSECLVL TYPE STRING,
PRIMARY_NAICS TYPE STRING,
REVENUE TYPE STRING,
EMPLNUM TYPE STRING,
LOCREVENUE TYPE STRING,
LOCEMPLNUM TYPE STRING,
FININST TYPE STRING,
ACCNTNO TYPE STRING,
ABAROUTE TYPE STRING,
ACCNTYP TYPE STRING,
LOCKBOX TYPE STRING,
AUTHDATE TYPE STRING,
EFTWAIVER TYPE STRING,
MERCHANTID1 TYPE STRING,
MERCHANTID2 TYPE STRING,
ACCNT_STATION TYPE STRING,
EDI TYPE STRING,
EDIVAN TYPE STRING,
EDIISAQ TYPE STRING,
EDIISASQ TYPE STRING,
EDIGS02 TYPE STRING,
EDIREC820 TYPE STRING,
EVSMLASTUPD TYPE STRING,
EVSMSTATUS TYPE STRING,
EVSOUTOFBUS TYPE STRING,
CREDCARD TYPE STRING,
CORRFLAG TYPE STRING,
MPIN TYPE STRING,
DEBTOFFSET TYPE STRING,
EXCLSTATFLAG TYPE STRING,
ANNUAL_IGT_REV TYPE STRING,
XUSNAM TYPE STRING,
XDATE TYPE STRING,
XTIME TYPE STRING,END OF T_EKKO_STR. DATA: WA_FMSAMVENDOR_HDR_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_FMSAMVENDOR_HDR_STR-MANDT sy-vline
WA_FMSAMVENDOR_HDR_STR-SAM_UE_ID sy-vline
WA_FMSAMVENDOR_HDR_STR-SAM_EFT_IND sy-vline
WA_FMSAMVENDOR_HDR_STR-DUNS sy-vline
WA_FMSAMVENDOR_HDR_STR-CAGE sy-vline
WA_FMSAMVENDOR_HDR_STR-DODAAC sy-vline
WA_FMSAMVENDOR_HDR_STR-PUR_REG_CODE sy-vline
WA_FMSAMVENDOR_HDR_STR-REGSTAT sy-vline
WA_FMSAMVENDOR_HDR_STR-REGDATE sy-vline
WA_FMSAMVENDOR_HDR_STR-EXPDATE sy-vline
WA_FMSAMVENDOR_HDR_STR-LASTUPDATE sy-vline
WA_FMSAMVENDOR_HDR_STR-ACTDATE sy-vline
WA_FMSAMVENDOR_HDR_STR-BUSNAME sy-vline
WA_FMSAMVENDOR_HDR_STR-DBANAME sy-vline
WA_FMSAMVENDOR_HDR_STR-DBOPENDATAFLG sy-vline
WA_FMSAMVENDOR_HDR_STR-SOURCE sy-vline
WA_FMSAMVENDOR_HDR_STR-DEPARTMENT_CODE sy-vline
WA_FMSAMVENDOR_HDR_STR-HIER_DEP_CODE sy-vline
WA_FMSAMVENDOR_HDR_STR-HIER_DEP_NAME sy-vline
WA_FMSAMVENDOR_HDR_STR-HIER_AGCY_CODE sy-vline
WA_FMSAMVENDOR_HDR_STR-HIER_AGCY_NAME sy-vline
WA_FMSAMVENDOR_HDR_STR-HIER_OFFICE_CODE sy-vline
WA_FMSAMVENDOR_HDR_STR-TAXPAYERNAME sy-vline
WA_FMSAMVENDOR_HDR_STR-TAXIDTYPE sy-vline
WA_FMSAMVENDOR_HDR_STR-TAXID sy-vline
WA_FMSAMVENDOR_HDR_STR-URL sy-vline
WA_FMSAMVENDOR_HDR_STR-DIVNAME sy-vline
WA_FMSAMVENDOR_HDR_STR-DIVNUM sy-vline
WA_FMSAMVENDOR_HDR_STR-BUSSTART sy-vline
WA_FMSAMVENDOR_HDR_STR-FISCEND sy-vline
WA_FMSAMVENDOR_HDR_STR-AGCY_BUS_PUR sy-vline
WA_FMSAMVENDOR_HDR_STR-ENTSTRUCT sy-vline
WA_FMSAMVENDOR_HDR_STR-STATEINC sy-vline
WA_FMSAMVENDOR_HDR_STR-COUNTRYINC sy-vline
WA_FMSAMVENDOR_HDR_STR-COSECLVL sy-vline
WA_FMSAMVENDOR_HDR_STR-EMSECLVL sy-vline
WA_FMSAMVENDOR_HDR_STR-PRIMARY_NAICS sy-vline
WA_FMSAMVENDOR_HDR_STR-REVENUE sy-vline
WA_FMSAMVENDOR_HDR_STR-EMPLNUM sy-vline
WA_FMSAMVENDOR_HDR_STR-LOCREVENUE sy-vline
WA_FMSAMVENDOR_HDR_STR-LOCEMPLNUM sy-vline
WA_FMSAMVENDOR_HDR_STR-FININST sy-vline
WA_FMSAMVENDOR_HDR_STR-ACCNTNO sy-vline
WA_FMSAMVENDOR_HDR_STR-ABAROUTE sy-vline
WA_FMSAMVENDOR_HDR_STR-ACCNTYP sy-vline
WA_FMSAMVENDOR_HDR_STR-LOCKBOX sy-vline
WA_FMSAMVENDOR_HDR_STR-AUTHDATE sy-vline
WA_FMSAMVENDOR_HDR_STR-EFTWAIVER sy-vline
WA_FMSAMVENDOR_HDR_STR-MERCHANTID1 sy-vline
WA_FMSAMVENDOR_HDR_STR-MERCHANTID2 sy-vline
WA_FMSAMVENDOR_HDR_STR-ACCNT_STATION sy-vline
WA_FMSAMVENDOR_HDR_STR-EDI sy-vline
WA_FMSAMVENDOR_HDR_STR-EDIVAN sy-vline
WA_FMSAMVENDOR_HDR_STR-EDIISAQ sy-vline
WA_FMSAMVENDOR_HDR_STR-EDIISASQ sy-vline
WA_FMSAMVENDOR_HDR_STR-EDIGS02 sy-vline
WA_FMSAMVENDOR_HDR_STR-EDIREC820 sy-vline
WA_FMSAMVENDOR_HDR_STR-EVSMLASTUPD sy-vline
WA_FMSAMVENDOR_HDR_STR-EVSMSTATUS sy-vline
WA_FMSAMVENDOR_HDR_STR-EVSOUTOFBUS sy-vline
WA_FMSAMVENDOR_HDR_STR-CREDCARD sy-vline
WA_FMSAMVENDOR_HDR_STR-CORRFLAG sy-vline
WA_FMSAMVENDOR_HDR_STR-MPIN sy-vline
WA_FMSAMVENDOR_HDR_STR-DEBTOFFSET sy-vline
WA_FMSAMVENDOR_HDR_STR-EXCLSTATFLAG sy-vline
WA_FMSAMVENDOR_HDR_STR-ANNUAL_IGT_REV sy-vline
WA_FMSAMVENDOR_HDR_STR-XUSNAM sy-vline
WA_FMSAMVENDOR_HDR_STR-XDATE sy-vline
WA_FMSAMVENDOR_HDR_STR-XTIME sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.