ABAP Select data from SAP table /PRA/WH_VN_PRF_T 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 /PRA/WH_VN_PRF_T 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 /PRA/WH_VN_PRF_T. 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 /PRA/WH_VN_PRF_T 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_/PRA/WH_VN_PRF_T TYPE STANDARD TABLE OF /PRA/WH_VN_PRF_T,
      WA_/PRA/WH_VN_PRF_T TYPE /PRA/WH_VN_PRF_T,
      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: </PRA/WH_VN_PRF_T> TYPE /PRA/WH_VN_PRF_T.

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

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM /PRA/WH_VN_PRF_T
  INTO TABLE IT_/PRA/WH_VN_PRF_T.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM /PRA/WH_VN_PRF_T
*  INTO TABLE @DATA(IT_/PRA/WH_VN_PRF_T2).
*--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_/PRA/WH_VN_PRF_T INDEX 1 INTO DATA(WA_/PRA/WH_VN_PRF_T2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/PRA/WH_VN_PRF_T ASSIGNING </PRA/WH_VN_PRF_T>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</PRA/WH_VN_PRF_T>-MANDT = 1.
</PRA/WH_VN_PRF_T>-VENDOR_NO = 1.
</PRA/WH_VN_PRF_T>-COUNTRY = 1.
</PRA/WH_VN_PRF_T>-REGION = 1.
</PRA/WH_VN_PRF_T>-TAX_ACC_NO = 1.
ENDLOOP.

LOOP AT IT_/PRA/WH_VN_PRF_T INTO WA_/PRA/WH_VN_PRF_T.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/PRA/WH_VN_PRF_T-TAXPAYER_NO, sy-vline,
WA_/PRA/WH_VN_PRF_T-TAXPAYER_NAME, sy-vline,
WA_/PRA/WH_VN_PRF_T-COMPANY_CODE, sy-vline,
WA_/PRA/WH_VN_PRF_T-REPORT_ID, sy-vline,
WA_/PRA/WH_VN_PRF_T-EFF_FROM_DATE, sy-vline,
WA_/PRA/WH_VN_PRF_T-EFF_TO_DATE, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/PRA/WH_VN_PRF_T 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_/PRA/WH_VN_PRF_T 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_/PRA/WH_VN_PRF_T INTO WA_/PRA/WH_VN_PRF_T. *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 VENDOR_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/PRA/WH_VN_PRF_T-VENDOR_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/PRA/WH_VN_PRF_T-VENDOR_NO.
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_/PRA/WH_VN_PRF_T_STR,
MANDT TYPE STRING,
VENDOR_NO TYPE STRING,
COUNTRY TYPE STRING,
REGION TYPE STRING,
TAX_ACC_NO TYPE STRING,
TAXPAYER_NO TYPE STRING,
TAXPAYER_NAME TYPE STRING,
COMPANY_CODE TYPE STRING,
REPORT_ID TYPE STRING,
EFF_FROM_DATE TYPE STRING,
EFF_TO_DATE TYPE STRING,
VENDOR_NAME TYPE STRING,
CONTACT_TITLE TYPE STRING,
CONTACT_NAME TYPE STRING,
CONTACT_PHONE TYPE STRING,
PHONE_EXT TYPE STRING,
FAX_NO TYPE STRING,
CONTACT_EMAIL TYPE STRING,
ADDRESS1 TYPE STRING,
ADDRESS2 TYPE STRING,
ADDRESS3 TYPE STRING,
CITY TYPE STRING,
ZIPCODE TYPE STRING,
SSN TYPE STRING,
OIU_CRUSER TYPE STRING,
OIU_TIMESTAMP TYPE STRING,
WH_RUN_ID TYPE STRING,END OF T_EKKO_STR. DATA: WA_/PRA/WH_VN_PRF_T_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_/PRA/WH_VN_PRF_T_STR-MANDT sy-vline
WA_/PRA/WH_VN_PRF_T_STR-VENDOR_NO sy-vline
WA_/PRA/WH_VN_PRF_T_STR-COUNTRY sy-vline
WA_/PRA/WH_VN_PRF_T_STR-REGION sy-vline
WA_/PRA/WH_VN_PRF_T_STR-TAX_ACC_NO sy-vline
WA_/PRA/WH_VN_PRF_T_STR-TAXPAYER_NO sy-vline
WA_/PRA/WH_VN_PRF_T_STR-TAXPAYER_NAME sy-vline
WA_/PRA/WH_VN_PRF_T_STR-COMPANY_CODE sy-vline
WA_/PRA/WH_VN_PRF_T_STR-REPORT_ID sy-vline
WA_/PRA/WH_VN_PRF_T_STR-EFF_FROM_DATE sy-vline
WA_/PRA/WH_VN_PRF_T_STR-EFF_TO_DATE sy-vline
WA_/PRA/WH_VN_PRF_T_STR-VENDOR_NAME sy-vline
WA_/PRA/WH_VN_PRF_T_STR-CONTACT_TITLE sy-vline
WA_/PRA/WH_VN_PRF_T_STR-CONTACT_NAME sy-vline
WA_/PRA/WH_VN_PRF_T_STR-CONTACT_PHONE sy-vline
WA_/PRA/WH_VN_PRF_T_STR-PHONE_EXT sy-vline
WA_/PRA/WH_VN_PRF_T_STR-FAX_NO sy-vline
WA_/PRA/WH_VN_PRF_T_STR-CONTACT_EMAIL sy-vline
WA_/PRA/WH_VN_PRF_T_STR-ADDRESS1 sy-vline
WA_/PRA/WH_VN_PRF_T_STR-ADDRESS2 sy-vline
WA_/PRA/WH_VN_PRF_T_STR-ADDRESS3 sy-vline
WA_/PRA/WH_VN_PRF_T_STR-CITY sy-vline
WA_/PRA/WH_VN_PRF_T_STR-ZIPCODE sy-vline
WA_/PRA/WH_VN_PRF_T_STR-SSN sy-vline
WA_/PRA/WH_VN_PRF_T_STR-OIU_CRUSER sy-vline
WA_/PRA/WH_VN_PRF_T_STR-OIU_TIMESTAMP sy-vline
WA_/PRA/WH_VN_PRF_T_STR-WH_RUN_ID sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.