ABAP Select data from SAP table FIWTID_S_XSD_INPUT_FILE_PPH22 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 FIWTID_S_XSD_INPUT_FILE_PPH22 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 FIWTID_S_XSD_INPUT_FILE_PPH22. 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 FIWTID_S_XSD_INPUT_FILE_PPH22 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_FIWTID_S_XSD_INPUT_FILE_PPH22 TYPE STANDARD TABLE OF FIWTID_S_XSD_INPUT_FILE_PPH22,
      WA_FIWTID_S_XSD_INPUT_FILE_PPH22 TYPE FIWTID_S_XSD_INPUT_FILE_PPH22,
      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: <FIWTID_S_XSD_INPUT_FILE_PPH22> TYPE FIWTID_S_XSD_INPUT_FILE_PPH22.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM FIWTID_S_XSD_INPUT_FILE_PPH22
*  INTO TABLE @DATA(IT_FIWTID_S_XSD_INPUT_FILE_PPH222).
*--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_FIWTID_S_XSD_INPUT_FILE_PPH22 INDEX 1 INTO DATA(WA_FIWTID_S_XSD_INPUT_FILE_PPH222).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_FIWTID_S_XSD_INPUT_FILE_PPH22 ASSIGNING <FIWTID_S_XSD_INPUT_FILE_PPH22>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<FIWTID_S_XSD_INPUT_FILE_PPH22>-FORMCODE = 1.
<FIWTID_S_XSD_INPUT_FILE_PPH22>-PERIOD = 1.
<FIWTID_S_XSD_INPUT_FILE_PPH22>-YEAR1 = 1.
<FIWTID_S_XSD_INPUT_FILE_PPH22>-CORRECTION_RUN = 1.
<FIWTID_S_XSD_INPUT_FILE_PPH22>-TAXNUMBER1 = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_FIWTID_S_XSD_INPUT_FILE_PPH22-NAME1, sy-vline,
WA_FIWTID_S_XSD_INPUT_FILE_PPH22-ADDRESS, sy-vline,
WA_FIWTID_S_XSD_INPUT_FILE_PPH22-CTNUMBER, sy-vline,
WA_FIWTID_S_XSD_INPUT_FILE_PPH22-BLDAT, sy-vline,
WA_FIWTID_S_XSD_INPUT_FILE_PPH22-GROSSAMT1, sy-vline,
WA_FIWTID_S_XSD_INPUT_FILE_PPH22-TAX_RATE1, sy-vline.
ENDLOOP. *Add any further fields from structure WA_FIWTID_S_XSD_INPUT_FILE_PPH22 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_FIWTID_S_XSD_INPUT_FILE_PPH22 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_FIWTID_S_XSD_INPUT_FILE_PPH22 INTO WA_FIWTID_S_XSD_INPUT_FILE_PPH22. *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_FIWTID_S_XSD_INPUT_FILE_PPH22_STR,
FORMCODE TYPE STRING,
PERIOD TYPE STRING,
YEAR1 TYPE STRING,
CORRECTION_RUN TYPE STRING,
TAXNUMBER1 TYPE STRING,
NAME1 TYPE STRING,
ADDRESS TYPE STRING,
CTNUMBER TYPE STRING,
BLDAT TYPE STRING,
GROSSAMT1 TYPE STRING,
TAX_RATE1 TYPE STRING,
TAX_AMT1 TYPE STRING,
GROSSAMT2 TYPE STRING,
TAX_RATE2 TYPE STRING,
TAX_AMT2 TYPE STRING,
GROSSAMT3 TYPE STRING,
TAX_RATE3 TYPE STRING,
TAX_AMT3 TYPE STRING,
GROSSAMT4 TYPE STRING,
TAX_RATE4 TYPE STRING,
TAX_AMT4 TYPE STRING,
INDUSTRY TYPE STRING,
GROSSAMT5 TYPE STRING,
TAX_RATE5 TYPE STRING,
TAX_AMT5 TYPE STRING,
INDUSTRY1 TYPE STRING,
GROSSAMT6 TYPE STRING,
TAX_RATE6 TYPE STRING,
TAX_AMT6 TYPE STRING,
SPACE1 TYPE STRING,
GROSSAMT7 TYPE STRING,
TAX_RATE7 TYPE STRING,
TAX_AMT7 TYPE STRING,
INDUSTRY2 TYPE STRING,
GROSSAMT8 TYPE STRING,
TAX_RATE8 TYPE STRING,
TAX_AMT8 TYPE STRING,
SPACE2 TYPE STRING,
GROSSAMT9 TYPE STRING,
TAX_RATE9 TYPE STRING,
TAX_AMT9 TYPE STRING,
INDUSTRY3 TYPE STRING,
GROSSAMT10 TYPE STRING,
TAX_RATE10 TYPE STRING,
TAX_AMT10 TYPE STRING,
SPACE3 TYPE STRING,
GROSSAMT11 TYPE STRING,
TAX_RATE11 TYPE STRING,
TAX_AMT11 TYPE STRING,
TOT_BASE_AMT TYPE STRING,
TOT_TAX_AMT TYPE STRING,END OF T_EKKO_STR. DATA: WA_FIWTID_S_XSD_INPUT_FILE_PPH22_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_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-FORMCODE sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-PERIOD sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-YEAR1 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-CORRECTION_RUN sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-TAXNUMBER1 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-NAME1 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-ADDRESS sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-CTNUMBER sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-BLDAT sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-GROSSAMT1 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-TAX_RATE1 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-TAX_AMT1 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-GROSSAMT2 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-TAX_RATE2 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-TAX_AMT2 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-GROSSAMT3 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-TAX_RATE3 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-TAX_AMT3 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-GROSSAMT4 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-TAX_RATE4 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-TAX_AMT4 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-INDUSTRY sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-GROSSAMT5 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-TAX_RATE5 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-TAX_AMT5 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-INDUSTRY1 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-GROSSAMT6 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-TAX_RATE6 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-TAX_AMT6 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-SPACE1 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-GROSSAMT7 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-TAX_RATE7 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-TAX_AMT7 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-INDUSTRY2 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-GROSSAMT8 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-TAX_RATE8 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-TAX_AMT8 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-SPACE2 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-GROSSAMT9 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-TAX_RATE9 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-TAX_AMT9 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-INDUSTRY3 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-GROSSAMT10 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-TAX_RATE10 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-TAX_AMT10 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-SPACE3 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-GROSSAMT11 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-TAX_RATE11 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-TAX_AMT11 sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-TOT_BASE_AMT sy-vline
WA_FIWTID_S_XSD_INPUT_FILE_PPH22_STR-TOT_TAX_AMT sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.