ABAP Select data from SAP table JBIUFEST 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 JBIUFEST 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 JBIUFEST. 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 JBIUFEST 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_JBIUFEST TYPE STANDARD TABLE OF JBIUFEST,
      WA_JBIUFEST TYPE JBIUFEST,
      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: <JBIUFEST> TYPE JBIUFEST.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM JBIUFEST
*  INTO TABLE @DATA(IT_JBIUFEST2).
*--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_JBIUFEST INDEX 1 INTO DATA(WA_JBIUFEST2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_JBIUFEST ASSIGNING <JBIUFEST>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<JBIUFEST>-BUKRS = 1.
<JBIUFEST>-RFHA = 1.
<JBIUFEST>-SGSART = 1.
<JBIUFEST>-SFHAART = 1.
<JBIUFEST>-KONTRH = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_JBIUFEST-EXTPARTNR, sy-vline,
WA_JBIUFEST-RDEALER, sy-vline,
WA_JBIUFEST-RREFKONT, sy-vline,
WA_JBIUFEST-RPORTB, sy-vline,
WA_JBIUFEST-ZUONR, sy-vline,
WA_JBIUFEST-RGARANT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_JBIUFEST 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_JBIUFEST 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_JBIUFEST INTO WA_JBIUFEST. *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.

*Conversion exit ALPHA, internal->external for field RFHA CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_JBIUFEST-RFHA IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_JBIUFEST-RFHA.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field KONTRH CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_JBIUFEST-KONTRH IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_JBIUFEST-KONTRH.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field RGARANT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_JBIUFEST-RGARANT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_JBIUFEST-RGARANT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field RMAID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_JBIUFEST-RMAID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_JBIUFEST-RMAID.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_JBIUFEST_STR,
BUKRS TYPE STRING,
RFHA TYPE STRING,
SGSART TYPE STRING,
SFHAART TYPE STRING,
KONTRH TYPE STRING,
EXTPARTNR TYPE STRING,
RDEALER TYPE STRING,
RREFKONT TYPE STRING,
RPORTB TYPE STRING,
ZUONR TYPE STRING,
RGARANT TYPE STRING,
TBEGRU TYPE STRING,
WGSCHFT TYPE STRING,
DBLFZ TYPE STRING,
DELFZ TYPE STRING,
DVTRAB TYPE STRING,
TVTRAB TYPE STRING,
GSPPART TYPE STRING,
NORDEXT TYPE STRING,
SKOART TYPE STRING,
DGUEL_KP TYPE STRING,
NSTUFE TYPE STRING,
PKOND TYPE STRING,
BKOND TYPE STRING,
SWHRKOND TYPE STRING,
SZBMETH TYPE STRING,
SRHYTHM TYPE STRING,
AMMRHY TYPE STRING,
ATTRHY TYPE STRING,
SFORTREG TYPE STRING,
DVALUT TYPE STRING,
SVULT TYPE STRING,
INCLEXLC TYPE STRING,
SVWERK TYPE STRING,
DFAELL TYPE STRING,
SFULT TYPE STRING,
SFWERK TYPE STRING,
SKALID TYPE STRING,
SKALID2 TYPE STRING,
SDWERK TYPE STRING,
AFGSTAGE TYPE STRING,
SZNSPRO TYPE STRING,
DZNSSTD TYPE STRING,
SINCLBE TYPE STRING,
SRNDNG TYPE STRING,
SFHAZBA TYPE STRING,
BZBETR TYPE STRING,
WZBETR TYPE STRING,
SSIGN TYPE STRING,
DZTERM TYPE STRING,
MODE TYPE STRING,
ZUOND TYPE STRING,
REFER TYPE STRING,
MERKM TYPE STRING,
SFRANZ TYPE STRING,
RMAID TYPE STRING,
JEXPOZINS TYPE STRING,
JSOFVERR TYPE STRING,
PPAYMENT TYPE STRING,
SKALID3 TYPE STRING,END OF T_EKKO_STR. DATA: WA_JBIUFEST_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_JBIUFEST_STR-BUKRS sy-vline
WA_JBIUFEST_STR-RFHA sy-vline
WA_JBIUFEST_STR-SGSART sy-vline
WA_JBIUFEST_STR-SFHAART sy-vline
WA_JBIUFEST_STR-KONTRH sy-vline
WA_JBIUFEST_STR-EXTPARTNR sy-vline
WA_JBIUFEST_STR-RDEALER sy-vline
WA_JBIUFEST_STR-RREFKONT sy-vline
WA_JBIUFEST_STR-RPORTB sy-vline
WA_JBIUFEST_STR-ZUONR sy-vline
WA_JBIUFEST_STR-RGARANT sy-vline
WA_JBIUFEST_STR-TBEGRU sy-vline
WA_JBIUFEST_STR-WGSCHFT sy-vline
WA_JBIUFEST_STR-DBLFZ sy-vline
WA_JBIUFEST_STR-DELFZ sy-vline
WA_JBIUFEST_STR-DVTRAB sy-vline
WA_JBIUFEST_STR-TVTRAB sy-vline
WA_JBIUFEST_STR-GSPPART sy-vline
WA_JBIUFEST_STR-NORDEXT sy-vline
WA_JBIUFEST_STR-SKOART sy-vline
WA_JBIUFEST_STR-DGUEL_KP sy-vline
WA_JBIUFEST_STR-NSTUFE sy-vline
WA_JBIUFEST_STR-PKOND sy-vline
WA_JBIUFEST_STR-BKOND sy-vline
WA_JBIUFEST_STR-SWHRKOND sy-vline
WA_JBIUFEST_STR-SZBMETH sy-vline
WA_JBIUFEST_STR-SRHYTHM sy-vline
WA_JBIUFEST_STR-AMMRHY sy-vline
WA_JBIUFEST_STR-ATTRHY sy-vline
WA_JBIUFEST_STR-SFORTREG sy-vline
WA_JBIUFEST_STR-DVALUT sy-vline
WA_JBIUFEST_STR-SVULT sy-vline
WA_JBIUFEST_STR-INCLEXLC sy-vline
WA_JBIUFEST_STR-SVWERK sy-vline
WA_JBIUFEST_STR-DFAELL sy-vline
WA_JBIUFEST_STR-SFULT sy-vline
WA_JBIUFEST_STR-SFWERK sy-vline
WA_JBIUFEST_STR-SKALID sy-vline
WA_JBIUFEST_STR-SKALID2 sy-vline
WA_JBIUFEST_STR-SDWERK sy-vline
WA_JBIUFEST_STR-AFGSTAGE sy-vline
WA_JBIUFEST_STR-SZNSPRO sy-vline
WA_JBIUFEST_STR-DZNSSTD sy-vline
WA_JBIUFEST_STR-SINCLBE sy-vline
WA_JBIUFEST_STR-SRNDNG sy-vline
WA_JBIUFEST_STR-SFHAZBA sy-vline
WA_JBIUFEST_STR-BZBETR sy-vline
WA_JBIUFEST_STR-WZBETR sy-vline
WA_JBIUFEST_STR-SSIGN sy-vline
WA_JBIUFEST_STR-DZTERM sy-vline
WA_JBIUFEST_STR-MODE sy-vline
WA_JBIUFEST_STR-ZUOND sy-vline
WA_JBIUFEST_STR-REFER sy-vline
WA_JBIUFEST_STR-MERKM sy-vline
WA_JBIUFEST_STR-SFRANZ sy-vline
WA_JBIUFEST_STR-RMAID sy-vline
WA_JBIUFEST_STR-JEXPOZINS sy-vline
WA_JBIUFEST_STR-JSOFVERR sy-vline
WA_JBIUFEST_STR-PPAYMENT sy-vline
WA_JBIUFEST_STR-SKALID3 sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.