ABAP Select data from SAP table JBIBSTW 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 JBIBSTW 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 JBIBSTW. 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 JBIBSTW 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_JBIBSTW TYPE STANDARD TABLE OF JBIBSTW,
      WA_JBIBSTW TYPE JBIBSTW,
      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: <JBIBSTW> TYPE JBIBSTW.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM JBIBSTW
*  INTO TABLE @DATA(IT_JBIBSTW2).
*--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_JBIBSTW INDEX 1 INTO DATA(WA_JBIBSTW2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_JBIBSTW ASSIGNING <JBIBSTW>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<JBIBSTW>-BUKRS = 1.
<JBIBSTW>-RFHA = 1.
<JBIBSTW>-NORDER = 1.
<JBIBSTW>-NORDEXT = 1.
<JBIBSTW>-RBAENINT = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_JBIBSTW-RBAENEXT, sy-vline,
WA_JBIBSTW-OBJNR, sy-vline,
WA_JBIBSTW-SFGTYP, sy-vline,
WA_JBIBSTW-RBESTO, sy-vline,
WA_JBIBSTW-RANL, sy-vline,
WA_JBIBSTW-RLDEPO, sy-vline.
ENDLOOP. *Add any further fields from structure WA_JBIBSTW 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_JBIBSTW 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_JBIBSTW INTO WA_JBIBSTW. *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_JBIBSTW-RFHA IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_JBIBSTW-RFHA.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit EXCRT, internal->external for field KDEVKU CALL FUNCTION 'CONVERSION_EXIT_EXCRT_OUTPUT' EXPORTING input = WA_JBIBSTW-KDEVKU IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_JBIBSTW-KDEVKU.
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_JBIBSTW_STR,
BUKRS TYPE STRING,
RFHA TYPE STRING,
NORDER TYPE STRING,
NORDEXT TYPE STRING,
RBAENINT TYPE STRING,
RBAENEXT TYPE STRING,
OBJNR TYPE STRING,
SFGTYP TYPE STRING,
RBESTO TYPE STRING,
RANL TYPE STRING,
RLDEPO TYPE STRING,
RPORTB TYPE STRING,
SSHLNG TYPE STRING,
DVTRAB TYPE STRING,
TVTRAB TYPE STRING,
DBESTAND TYPE STRING,
DVALUT TYPE STRING,
DEFVALUT TYPE STRING,
DDISPO TYPE STRING,
ASTUECK TYPE STRING,
BNWHR TYPE STRING,
SNWHR TYPE STRING,
BBWHR TYPE STRING,
SBWHR TYPE STRING,
BSWHR TYPE STRING,
SSWHR TYPE STRING,
SRUNIT TYPE STRING,
LWAERS TYPE STRING,
BHWHR TYPE STRING,
SHWHR TYPE STRING,
BPWKURS TYPE STRING,
BPRICE TYPE STRING,
VVBASIS TYPE STRING,
KDEVKU TYPE STRING,
IEFFZS TYPE STRING,
SBAENTYP TYPE STRING,
SBEWART TYPE STRING,
SCOUPON TYPE STRING,
SSTCKKZ TYPE STRING,
SSTCKTG TYPE STRING,
SFLAT TYPE STRING,
SINCL TYPE STRING,
SSTORNO TYPE STRING,
SBERFIMA TYPE STRING,
SBKTYP TYPE STRING,
SZUABKNZ TYPE STRING,
SSAMKZ TYPE STRING,
DSAMM TYPE STRING,
OBJNRSAM TYPE STRING,END OF T_EKKO_STR. DATA: WA_JBIBSTW_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_JBIBSTW_STR-BUKRS sy-vline
WA_JBIBSTW_STR-RFHA sy-vline
WA_JBIBSTW_STR-NORDER sy-vline
WA_JBIBSTW_STR-NORDEXT sy-vline
WA_JBIBSTW_STR-RBAENINT sy-vline
WA_JBIBSTW_STR-RBAENEXT sy-vline
WA_JBIBSTW_STR-OBJNR sy-vline
WA_JBIBSTW_STR-SFGTYP sy-vline
WA_JBIBSTW_STR-RBESTO sy-vline
WA_JBIBSTW_STR-RANL sy-vline
WA_JBIBSTW_STR-RLDEPO sy-vline
WA_JBIBSTW_STR-RPORTB sy-vline
WA_JBIBSTW_STR-SSHLNG sy-vline
WA_JBIBSTW_STR-DVTRAB sy-vline
WA_JBIBSTW_STR-TVTRAB sy-vline
WA_JBIBSTW_STR-DBESTAND sy-vline
WA_JBIBSTW_STR-DVALUT sy-vline
WA_JBIBSTW_STR-DEFVALUT sy-vline
WA_JBIBSTW_STR-DDISPO sy-vline
WA_JBIBSTW_STR-ASTUECK sy-vline
WA_JBIBSTW_STR-BNWHR sy-vline
WA_JBIBSTW_STR-SNWHR sy-vline
WA_JBIBSTW_STR-BBWHR sy-vline
WA_JBIBSTW_STR-SBWHR sy-vline
WA_JBIBSTW_STR-BSWHR sy-vline
WA_JBIBSTW_STR-SSWHR sy-vline
WA_JBIBSTW_STR-SRUNIT sy-vline
WA_JBIBSTW_STR-LWAERS sy-vline
WA_JBIBSTW_STR-BHWHR sy-vline
WA_JBIBSTW_STR-SHWHR sy-vline
WA_JBIBSTW_STR-BPWKURS sy-vline
WA_JBIBSTW_STR-BPRICE sy-vline
WA_JBIBSTW_STR-VVBASIS sy-vline
WA_JBIBSTW_STR-KDEVKU sy-vline
WA_JBIBSTW_STR-IEFFZS sy-vline
WA_JBIBSTW_STR-SBAENTYP sy-vline
WA_JBIBSTW_STR-SBEWART sy-vline
WA_JBIBSTW_STR-SCOUPON sy-vline
WA_JBIBSTW_STR-SSTCKKZ sy-vline
WA_JBIBSTW_STR-SSTCKTG sy-vline
WA_JBIBSTW_STR-SFLAT sy-vline
WA_JBIBSTW_STR-SINCL sy-vline
WA_JBIBSTW_STR-SSTORNO sy-vline
WA_JBIBSTW_STR-SBERFIMA sy-vline
WA_JBIBSTW_STR-SBKTYP sy-vline
WA_JBIBSTW_STR-SZUABKNZ sy-vline
WA_JBIBSTW_STR-SSAMKZ sy-vline
WA_JBIBSTW_STR-DSAMM sy-vline
WA_JBIBSTW_STR-OBJNRSAM sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.