Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Extract data to a text file

Former Member
0 Likes
6,056

Hello,

My query is that i have developed a report and in the output i have placed check box to choose the document number which are to be printed. Now when i tick the document number only that document number should get stored in a text file which im extracting.... i' am able to get the text file and also the necessary data but how to get the selected document into the same text file...

Note:I need to tick the required document and hit preview button and the selected to be stored in the downloaded text file.

Attaching screenshot for ref...

Thanks in advance.

Regards,

Sam.

1 ACCEPTED SOLUTION
Read only

ipravir
Active Contributor
0 Likes
4,888

Hi Samual,

You can use the Raheem Code to store the selected row information in Text file.

And in the SAVE IN TEXT FILE logic, you can use the GUI_DOWNLOAD Function module and while calling the function module pass the 'X" value for the APPEND import parameters, so the all selected information will store into the selected or new text file.

Regards.

Praveer.

Hello,

My query is that i have developed a report and in the output i have placed check box to choose the document number which are to be printed. Now when i tick the document number only that document number should get stored in a text file which im extracting.... i' am able to get the text file and also the necessary data but how to get the selected document into the same text file...

Note:I need to tick the required document and hit preview button and the selected to be stored in the downloaded text file.

Attaching screenshot for ref...

Thanks in advance.

Regards,

Sam.

21 REPLIES 21
Read only

archanapawar
Contributor
0 Likes
4,888

Hi Sam,

You need to use function module GUI_DOWNLOAD (download to presentation server) or OPEN_DATASET (Download to application server), on event on 'PREVIEW' button click.

You must be having internal table which displays the screen you have displayed in screenshot.

You need to use the same table to check which check boxes are checked and take that data into new internal table. Download it using GUI_DOWNLOAD or OPEN_DATASET.

Hope its clear to you.

Read only

0 Likes
4,888

Hi Archana,

Thanks for your reply. i have already used gui_download and got  "order No, date and time" in the text file so again should i use gui_download?

Read only

0 Likes
4,888

Hi Sam,

I guess I didn't get your issue. You are already using GUI_DOWNLOAD, but you are unable to download the file. Is this your issue?

Where are you calling GUI_DOWNLOAD and are you executing the program in foreground?

Read only

0 Likes
4,888

Yes Archana i 'am already using the gui_download and getting few data. But my requirement is now when i tick the selected file that document number also should get stored in the text file. Hope your are clear.

Read only

0 Likes
4,888

Hi Sam,

You should use GUI_DOWNLOAD at the event when you check checkboxes. I guess you are using it before in your program to get complete list, but now you want specific documents to be downloaded.

Yes, in this case you will have to use GUI_DOWNLOAD again.

Read only

0 Likes
4,888

Archana i used the fm after the event. Ill try using the gui_download once again and let you know.

Read only

0 Likes
4,888

Archana,

Tried and im only getting the same data which is downloaded already. The selected doc no did not get stored in the text file.

Read only

0 Likes
4,888

Hi Sam,

Are you able to get itmes which are checked? You will get it in user command, as described by Abdul below.

Your internal table will be modified with the selected checkboxes. Are you able to achieve this first?

Read only

0 Likes
4,888

SELECT  a~aufnr a~plnbez
           b~dokar b~doknr b~doktl b~dokvr
           c~dktxt
           FROM afko AS a
           INNER JOIN drad AS b ON a~plnbez = b~objky
           INNER JOIN drat AS c ON b~doknr = c~doknr
                      AND b~dokar = c~dokar
                      AND b~dokvr = c~dokvr
                      AND b~doktl = c~doktl
           INTO CORRESPONDING FIELDS OF TABLE itab
           WHERE a~aufnr IN aufnr.

   SORT itab BY dokar.
   DELETE ADJACENT DUPLICATES FROM itab.

   SHIFT aufnr-low LEFT DELETING LEADING '0'.

   CONCATENATE 'order:' aufnr-low sy-uname sy-datum sy-uzeit
            INTO order SEPARATED BY ' '.

   APPEND order TO itab2.

ENDFORM.                    "data

*&---------------------------------------------------------------------*
*&      Form  build
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM build.

   CLEAR wfcat.

   wfcat-fieldname = 'CHKBOX'.
   wfcat-seltext_l = 'Print'.
   wfcat-checkbox = 'X'.
   wfcat-edit = 'X'.
   wfcat-input = 'X'.
*  wfcat-outputlen = 5.
   APPEND wfcat TO ifcat.
   CLEAR wfcat.

   wfcat-fieldname = 'DOKNR'.
   wfcat-seltext_l = 'Document number'.
   wfcat-outputlen = 25.
   APPEND wfcat TO ifcat.
   CLEAR wfcat.

   wfcat-fieldname = 'DKTXT'.
   wfcat-seltext_l = 'Document Description'.
   wfcat-outputlen = 45.
   APPEND wfcat TO ifcat.
   CLEAR wfcat.

   wfcat-fieldname = 'DOKAR'.
   wfcat-seltext_l = 'Document Type'.
   APPEND wfcat TO ifcat.
   CLEAR wfcat.

   wfcat-fieldname = 'DOKVR'.
   wfcat-seltext_l = 'Status Type'.
   APPEND wfcat TO ifcat.
   CLEAR wfcat.

   wfcat-fieldname = 'DOKTL'.
   wfcat-seltext_l = 'Document Part'.
   wfcat-outputlen = 15.
   APPEND wfcat TO ifcat.
   CLEAR wfcat.

   wfcat-fieldname = 'PLNBEZ'.
   wfcat-seltext_l = 'DMS Document.'.
   wfcat-outputlen = 40.
   APPEND wfcat TO ifcat.
   CLEAR wfcat.


ENDFORM.                    "build

*&---------------------------------------------------------------------*
*&      Form  disp
*&---------------------------------------------------------------------*

FORM disp.

   LOOP AT itab.

     CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
       EXPORTING
         i_callback_program       = sy-repid
         i_callback_pf_status_set = 'STANDARD'
         i_callback_user_command  = 'USR_COMMAND'
         it_fieldcat              = ifcat[]
         is_variant               = i_variant
         it_events                = i_events[]
         is_print                 = i_print
         i_default                = 'X'
         i_save                   = 'A'
       TABLES
         t_outtab                 = itab.
     IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
     ENDIF.

   ENDLOOP.

ENDFORM.                    "disp

*&---------------------------------------------------------------------*
*&      Form  STANDARD
*&---------------------------------------------------------------------*
FORM standard USING rt_extab TYPE slis_t_extab.

   SET PF-STATUS 'STANDARD'.

ENDFORM.                    "STANDARD
*&---------------------------------------------------------------------*
*&      Form  user_command
*&---------------------------------------------------------------------*
FORM usr_command USING f2code LIKE sy-ucomm
                        selfield TYPE slis_selfield.

   CASE f2code.

     WHEN 'BCK'.
       LEAVE PROGRAM.
       EXIT.

     WHEN 'BACK' OR 'CANCEL' OR 'EXIT'.
       LEAVE PROGRAM.
       CLEAR: f2code.

     WHEN 'PRV'.

       LOOP AT itab WHERE chkbox = 'X'.
         IF itab-chkbox NE ' '.


***          CALL FUNCTION 'DOCUMENT_SHOW_DIRECT'
***            EXPORTING
***              dokar   = itab-dokar
***              doknr   = itab-doknr
***              dokteil = itab-doktl
***              dokvr   = itab-dokvr.
***
***          IF sy-subrc <> 0.
****          MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
****          WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 .
***          ENDIF.
***
***        ENDIF.
***
***      ENDLOOP.
***      selfield-refresh = 'X'.
***
***    WHEN 'PNT'.
data:order TYPE string.

Read only

0 Likes
4,888

Hi Sam,

Use below FMs to check the changed data.

Data: L_V_REF_GRID  TYPE REF TO CL_GUI_ALV_GRID

CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'

      IMPORTING

        E_GRID = L_V_REF_GRID.

  IF NOT L_V_REF_GRID IS INITIAL.

    CALL METHOD L_V_REF_GRID->CHECK_CHANGED_DATA.

  ENDIF.

Then loop at your internal table

LOOP AT itab WHERE chkbox = 'X'.

Read only

Former Member
0 Likes
4,888

hi samuel,

I think you should use fm 'REUSE_ALV_LIST_DISPLAY'.

in that you can make use of user_command.

you can get all document numbers which are selected and save it in text file.

FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM

      RS_SELFIELD TYPE SLIS_SELFIELD.

  RS_SELFIELD-REFRESH = 'X'.

  CASE R_UCOMM.

    LOOP AT T_FINAL INTO WA_FINAL.

      IF WA_FINAL-CHKBOX = 'X'.

             SAVE IN TEXT FILE (CODING HAS TO BE DONE)

      END IF.

    ENDLOOP.

  ENDCASE.

ENDFORM.                               " USER_COMMAND

Read only

0 Likes
4,888

Adbul,

I have used this FM also.

Read only

ipravir
Active Contributor
0 Likes
4,889

Hi Samual,

You can use the Raheem Code to store the selected row information in Text file.

And in the SAVE IN TEXT FILE logic, you can use the GUI_DOWNLOAD Function module and while calling the function module pass the 'X" value for the APPEND import parameters, so the all selected information will store into the selected or new text file.

Regards.

Praveer.

Read only

Former Member
0 Likes
4,888

Praveen tried and not getting it. Could suggest please.

Read only

ipravir
Active Contributor
0 Likes
4,888

Hi Samuel,

Please find the Below Code.

Loop at it_table into <FS> where checkbox = 'X'.

append <FS> to Dummy_tab.

Call Function 'GUI_DOWNLOAD'

exporting

     filename  = g_filename

     filetype    = 'ASC'

     Append   = 'X'

tables

     data_tab = Dummy_tab.

Refresh: dummy_tab.

Endloop.

Regards.

Praveer.

Read only

Former Member
0 Likes
4,888

Thanks Praveen your method worked.

Read only

Former Member
0 Likes
4,888

Can you share your source where you are trying to fetch and store in a text file.

Read only

0 Likes
4,888

SELECT  a~aufnr a~plnbez
           b~dokar b~doknr b~doktl b~dokvr
           c~dktxt
           FROM afko AS a
           INNER JOIN drad AS b ON a~plnbez = b~objky
           INNER JOIN drat AS c ON b~doknr = c~doknr
                      AND b~dokar = c~dokar
                      AND b~dokvr = c~dokvr
                      AND b~doktl = c~doktl
           INTO CORRESPONDING FIELDS OF TABLE itab
           WHERE a~aufnr IN aufnr.

   SORT itab BY dokar.
   DELETE ADJACENT DUPLICATES FROM itab.

   SHIFT aufnr-low LEFT DELETING LEADING '0'.

   CONCATENATE 'order:' aufnr-low sy-uname sy-datum sy-uzeit
            INTO order SEPARATED BY ' '.

   APPEND order TO itab2.

ENDFORM.                    "data

*&---------------------------------------------------------------------*
*&      Form  build
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM build.

   CLEAR wfcat.

   wfcat-fieldname = 'CHKBOX'.
   wfcat-seltext_l = 'Print'.
   wfcat-checkbox = 'X'.
   wfcat-edit = 'X'.
   wfcat-input = 'X'.
*  wfcat-outputlen = 5.
   APPEND wfcat TO ifcat.
   CLEAR wfcat.

   wfcat-fieldname = 'DOKNR'.
   wfcat-seltext_l = 'Document number'.
   wfcat-outputlen = 25.
   APPEND wfcat TO ifcat.
   CLEAR wfcat.

   wfcat-fieldname = 'DKTXT'.
   wfcat-seltext_l = 'Document Description'.
   wfcat-outputlen = 45.
   APPEND wfcat TO ifcat.
   CLEAR wfcat.

   wfcat-fieldname = 'DOKAR'.
   wfcat-seltext_l = 'Document Type'.
   APPEND wfcat TO ifcat.
   CLEAR wfcat.

   wfcat-fieldname = 'DOKVR'.
   wfcat-seltext_l = 'Status Type'.
   APPEND wfcat TO ifcat.
   CLEAR wfcat.

   wfcat-fieldname = 'DOKTL'.
   wfcat-seltext_l = 'Document Part'.
   wfcat-outputlen = 15.
   APPEND wfcat TO ifcat.
   CLEAR wfcat.

   wfcat-fieldname = 'PLNBEZ'.
   wfcat-seltext_l = 'DMS Document.'.
   wfcat-outputlen = 40.
   APPEND wfcat TO ifcat.
   CLEAR wfcat.


ENDFORM.                    "build

*&---------------------------------------------------------------------*
*&      Form  disp
*&---------------------------------------------------------------------*

FORM disp.

   LOOP AT itab.

     CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
       EXPORTING
         i_callback_program       = sy-repid
         i_callback_pf_status_set = 'STANDARD'
         i_callback_user_command  = 'USR_COMMAND'
         it_fieldcat              = ifcat[]
         is_variant               = i_variant
         it_events                = i_events[]
         is_print                 = i_print
         i_default                = 'X'
         i_save                   = 'A'
       TABLES
         t_outtab                 = itab.
     IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
     ENDIF.

   ENDLOOP.

ENDFORM.                    "disp

*&---------------------------------------------------------------------*
*&      Form  STANDARD
*&---------------------------------------------------------------------*
FORM standard USING rt_extab TYPE slis_t_extab.

   SET PF-STATUS 'STANDARD'.

ENDFORM.                    "STANDARD
*&---------------------------------------------------------------------*
*&      Form  user_command
*&---------------------------------------------------------------------*
FORM usr_command USING f2code LIKE sy-ucomm
                        selfield TYPE slis_selfield.

   CASE f2code.

     WHEN 'BCK'.
       LEAVE PROGRAM.
       EXIT.

     WHEN 'BACK' OR 'CANCEL' OR 'EXIT'.
       LEAVE PROGRAM.
       CLEAR: f2code.

     WHEN 'PRV'.

       LOOP AT itab WHERE chkbox = 'X'.
         IF itab-chkbox NE ' '.


***          CALL FUNCTION 'DOCUMENT_SHOW_DIRECT'
***            EXPORTING
***              dokar   = itab-dokar
***              doknr   = itab-doknr
***              dokteil = itab-doktl
***              dokvr   = itab-dokvr.
***
***          IF sy-subrc <> 0.
****          MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
****          WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 .
***          ENDIF.
***
***        ENDIF.
***
***      ENDLOOP.
***      selfield-refresh = 'X'.
***
***    WHEN 'PNT'.
data:order TYPE string.

Read only

0 Likes
4,888

Hi Samuel,

Use below FM to download the drawings to local system.

ITAB TYPE STANDARD TABLE OF BAPI_DOC_APPLICATIONS WITH HEADER LINE,
       DOC TYPE STANDARD TABLE OF BAPI_DOC_DRAW2 WITH HEADER LINE,
       RETN TYPE BAPIRET2,
       DOCFILE TYPE STANDARD TABLE OF BAPI_DOC_FILES2 WITH HEADER LINE.

CALL FUNCTION 'BAPI_DOCUMENT_CHECKOUTVIEWX'
*        EXPORTING
*          GETCOMPONENTS     = '1'
*         ORIGINALPATH      = ' '
*         HOSTNAME          = ' '
*         PF_HTTP_DEST      = ' '
*         PF_FTP_DEST       = ' '
     IMPORTING
       RETURN            = RETN
     TABLES
       DOCUMENTS         = DOC
*          DOCUMENTFILES_IN  = DOCFILE
        DOCUMENTFILES_OUT = DOCFILE
       WSAPPLICATION     = ITAB.


Arivazhagan S

Read only

0 Likes
4,888

Please use this code for your reference.

Note:Make sure when you select the checkbox after that dont forget to click on SAVE button of screen.  

*&---------------------------------------------------------------------*
*& Report  Z_DEMO1
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  z_demo1.

TYPES:BEGIN OF t_mara,


      matnr TYPE matnr"Material NUmber
      matkl TYPE matkl,   "Material type
      cbox TYPE checkbox,
      END OF t_mara.

DATA :it_mara TYPE STANDARD TABLE OF t_mara,
      wa_mara TYPE t_mara,
      it_mara1 TYPE STANDARD TABLE OF t_mara,
      wa_mara1 TYPE t_mara,
      it_fieldcat TYPE  slis_t_fieldcat_alv,
      wa_fieldcat TYPE slis_fieldcat_alv.


SELECT   matnr
         matkl
         FROM mara
         INTO CORRESPONDING FIELDS OF TABLE it_mara UP TO 10 ROWS.

CLEAR wa_fieldcat.
wa_fieldcat-tabname = 'IT_MARA'.
wa_fieldcat-fieldname = 'CBOX'.
wa_fieldcat-col_pos = '1'.
wa_fieldcat-checkbox = 'X'.
wa_fieldcat-edit = 'X'.
APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-tabname = 'IT_MARA'.
wa_fieldcat-fieldname = 'MATNR'.
wa_fieldcat-col_pos = 1.
APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.
wa_fieldcat-tabname = 'IT_MARA'.
wa_fieldcat-fieldname = 'MATKL'.
wa_fieldcat-col_pos = 1.
APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    it_fieldcat   = it_fieldcat
  TABLES
    t_outtab      = it_mara
  EXCEPTIONS
    program_error = 1
    OTHERS        = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.


DATA : ref_grid TYPE REF TO cl_gui_alv_grid. "new

IF ref_grid IS INITIAL.
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = ref_grid.
ENDIF.

IF NOT ref_grid IS INITIAL.
  CALL METHOD ref_grid->check_changed_data.
ENDIF.




LOOP AT it_mara INTO wa_mara.

  IF wa_mara-cbox = 'X'.

    wa_mara1-matnr =   wa_mara-matnr.
    wa_mara1-matkl =   wa_mara-matkl.
    APPEND wa_mara1 TO it_mara1.
    CLEAR: wa_mara1 , wa_mara.
  ENDIF.

ENDLOOP.





CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
    filename                = 'D:\Demo.txt'
    filetype                = 'ASC'
  TABLES
    data_tab                = it_mara1
  EXCEPTIONS
    file_write_error        = 1
    no_batch                = 2
    gui_refuse_filetransfer = 3
    invalid_type            = 4
    no_authority            = 5
    unknown_error           = 6
    header_not_allowed      = 7
    separator_not_allowed   = 8
    filesize_not_allowed    = 9
    header_too_long         = 10
    dp_error_create         = 11
    dp_error_send           = 12
    dp_error_write          = 13
    unknown_dp_error        = 14
    access_denied           = 15
    dp_out_of_memory        = 16
    disk_full               = 17
    dp_timeout              = 18
    file_not_found          = 19
    dataprovider_exception  = 20
    control_flush_error     = 21
    OTHERS                  = 22.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

Read only

Former Member
0 Likes
4,888

Thanks Everybody for all your help and timely support.

Cheers

Sam.